package com.iflysse.dao;

import com.iflysse.pojo.po.common.CommonPoResp;
import com.iflysse.pojo.po.req.StudentHeadImagePoReq;
import com.iflysse.pojo.po.req.StudentPoReq;
import com.iflysse.pojo.po.req.TeacherClassIdPoReq;
import com.iflysse.pojo.po.req.UserIdPoReq;
import com.iflysse.pojo.po.resp.StudentPlainPoResp;
import com.iflysse.pojo.po.resp.StudentPoResp;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.List;

@Repository
public interface StudentDao {
    /**
     * 根据教学班级编号获取学生编号
     * @param teacherClassIdPoReq
     * @return
     */
    @Select({"select student_id from tb_teaching_class_student where teaching_class_id = #{teachingClassId} and is_delete = 0"})
    List<String> getStudentIdListByTeacherClass(TeacherClassIdPoReq teacherClassIdPoReq) throws SQLException;

    /**
     * 根据学生学号获取学生信息
     * @param studentIdList
     * @return
     */
    @Select( " <script>" +
            "select * from tb_student where student_id in  " +
            " <foreach collection='studentIdList' open='(' item='studentId' separator=',' close=')'> #{studentId}</foreach> "+
            " </script>" )
    @Results({
            @Result(property = "studentId",column = "student_id"),
            @Result(property = "studentName",column = "student_name"),
            @Result(property = "headImage",column = "head_image"),
            @Result(property = "accountId",column = "account_id"),
            @Result(property = "classNo",column = "class_no"),
    })
    List<StudentPoResp> getStudentListByStudentIdList(List<String> studentIdList) throws SQLException;

    /**
     * 用户选择行政班级,查询该行政班级下的学生信息
     * @param classNo 行政班
     * @return
     */
    @Select({"select student_id,student_name,number from tb_student where class_no = #{classNo}"})
    @Results({
            @Result(property = "studentId",column = "student_id"),
            @Result(property = "studentName",column = "student_name"),
            @Result(property = "headImage",column = "head_image"),
    })
    List<StudentPlainPoResp> getStudentPlainListByClassName(String classNo) throws SQLException;

    /**
     * 修改学生信息
     * @param studentPoReq
     * @return
     */
    @Update("update tb_student" +
            " set nick_name = #{nick_name}, student_name=#{student_name}, gender=#{gender}, email=#{email}, hobbies=#{hobbies}, personal_signature=#{personal_signature} where student_id = #{studentId}")
    int updateStudent(StudentPoReq studentPoReq) throws SQLException;

    /**
     * 修改学生头像
     * @param studentHeadImagePoReq
     * @return
     */
    @Update("update tb_student set head_image  = #{headImagePath} where student_id = #{studentId}")
    int updateHeadImage4Student(StudentHeadImagePoReq studentHeadImagePoReq) throws SQLException;

    /**
     * 根据账户编号查询学生信息
     * @param userIdPoReq
     * @return
     */
    @Select({"select * from tb_student where account_id = #{accountId}"})
    @Results({
            @Result(property = "studentId",column = "student_id"),
            @Result(property = "nickName",column = "nick_name"),
            @Result(property = "name",column = "name"),
            @Result(property = "gender",column = "gender"),
            @Result(property = "personalSignature",column = "personal_signature"),
            @Result(property = "email",column = "email"),
            @Result(property = "headImage",column = "head_image"),
            @Result(property = "accountId",column = "account_id"),
    })
    StudentPoResp getStudentByAccountId(UserIdPoReq userIdPoReq) throws SQLException;

    /**
     * 根据账户编号查询学生姓名
     * @param account_id
     * @return
     */
    @Select({"select student_name from tb_student where account_id = #{account_id}"})
    String getStudentNameByAccountId(String account_id) throws SQLException;


    /**
     * 根据学生编号查询学生信息
     * @param studentId
     * @return
     */
    @Select({"select * from tb_student where student_id = #{studentId}"})
    @Results({
            @Result(property = "studentId",column = "student_id"),
            @Result(property = "nickName",column = "nick_name"),
            @Result(property = "studentName",column = "student_name"),
            @Result(property = "gender",column = "gender"),
            @Result(property = "personalSignature",column = "personal_signature"),
            @Result(property = "email",column = "email"),
            @Result(property = "headImage",column = "head_image"),
            @Result(property = "accountId",column = "account_id"),
    })
    StudentPoResp getStudentByStudentId(String studentId) throws SQLException;

}
